package com.itheima.注解;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class Demo {
    public static void main(String[] args) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, InvocationTargetException, InstantiationException {
        Class c = Class.forName("com.itheima.注解.Mymethod");
        Method[] m = c.getMethods();
        Constructor con = c.getConstructor();
        Object o = con.newInstance();
        for (Method method : m) {
            if(method.isAnnotationPresent(Test.class)){
                try {
                    method.invoke(o);
                    System.out.println(method.getName()+"没有异常");
                } catch (Exception e) {
                    String s = e.getCause().toString();
                    System.out.println(method.getName()+"的异常是:"+s);
                }
            }
        }
    }
}
